package h0908;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Subsets {
    public static void main(String[] args) {
        int[] nums={1,2,2,3};
        System.out.println(subsets(nums));
    }
    public static List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res=new ArrayList<>();
        LinkedList<Integer> temp=new LinkedList<>();
        backTrack(res,temp,nums,0,nums.length);
        return res;
    }

    private static void backTrack(List<List<Integer>> res, LinkedList<Integer> temp, int[] nums,int start, int length) {
        res.add(new LinkedList<>(temp));
        for (int i = start; i < length; i++) {
            if (i>start&&nums[i]==nums[i-1]) continue;
            temp.addLast(nums[i]);
            backTrack(res, temp, nums, i+1, length);
            temp.removeLast();
        }
    }
}
